﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MebApp.Launcher
{
    public static class MessageBoxExtension
    {
        public static DialogResult MessageBoxShow(this Control control, string message, MessageBoxButtons buttons = MessageBoxButtons.OK)
        {
            if (control.InvokeRequired)
            {
                return (DialogResult)control.Invoke(new Func<DialogResult>(() =>
                {
                    return MessageBoxShow(control, message, buttons);
                }));
            }
            var form = control.FindForm();
            return MessageBox.Show(form, message, form.Text, buttons);
        }

        public static DialogResult DialogShow<T>(this Form form, params object[] args)
        {
            var dialogForm = (Form)Activator.CreateInstance(typeof(T), args);
            dialogForm.StartPosition = FormStartPosition.CenterParent;
            return dialogForm.ShowDialog(form);
        }
    }
}
